/*****************************************************
 * @author heshuaibiao
 * @version 1.0
 * create 2007.1.18
******************************************************/
var letterWidth = {EW:"", CW:""};
function findId(elementId) {
	return document.getElementById(elementId);
}

function omitById(spanId, omitSign) {
	span_temp = findId(spanId);
	td_temp = getElementTd(span_temp);
	if (td_temp == "error") {
		alert("textomitor component must insert into table");
		return false;
	} else {
		span_temp.innerText = span_value(td_temp, span_temp, omitSign); // IE
		span_temp.textContent = span_value(td_temp, span_temp, omitSign); // Firefox
	}
}
var omitSign = "...";
function omitBySpanObject(spanOjb){
	var td_temp = getElementTd(spanOjb);
	if (td_temp == "error") {
		alert("textomitor component must insert into table");
		return false;
	} else {
		spanOjb.innerText = span_value(td_temp, spanOjb, omitSign); // IE
		// spanOjb.textContent = span_value(td_temp, spanOjb, omitSign); // Firefox
	}
}

function initOmitor(){
    var spans = document.getElementsByName("hsbPrompt");
	var slength = spans.length;
	for(var i = 0; i < slength; i++){
		// spans[i].onclick = function(){this.parentElement.parentElement.click()};
		omitBySpanObject(spans[i]);
	}
}


function getElementTd(temp_value) {
	var temp = temp_value.parentNode;
	var tempName = temp.tagName;
	if (tempName == "TD") {
		return temp;
	}
	if (tempName == "BODY") {
		return "error";
	}
	return getElementTd(temp);
}

function span_value(td_1, span_1, omitSign) {
	td_length = td_1.offsetWidth;
	s = span_1.title;
	if (letterWidth.EW == "") {
		setLetterWidth();
	}
	var intCount = letterWidth.EW * omitSign.length;
	for (var i = 0; Math.min(i, s.length) != s.length; i++) {
		if (s.charCodeAt(i) > 255) {
			intCount += letterWidth.CW;
		} else {
			intCount += letterWidth.EW;
		}
		if (intCount > td_length) {
			break;
		}
	}
	re = /\r\n/g;
	span_1.title = span_1.title.replace(re, " ");
	if (Math.min(i, span_1.title.length) != span_1.title.length) {
		return span_1.title.substr(0, i) + omitSign;
	} else {
		return span_1.title;
	}
}

function getLetterWidth(letter) {
	var span = document.createElement("span");
	span.textContent = letter;
	span.innerText = letter;
	document.body.appendChild(span);
	var temp = span.offsetWidth;
	document.body.removeChild(span);
	return temp;
}

function setLetterWidth() {
	letterWidth.EW = getLetterWidth("A");
	letterWidth.CW = getLetterWidth("\u8d3a");
}
var omitOnload = window.onload;
window.onload = function () { if(omitOnload) omitOnload(); initOmitor();}

